<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			/*
			async 定义函数
			await 的返回值必须是一个Promise对象, 只有前一个await的promise进入
			      resolve状态时，才会执行下一个await
			
			*/
			function getData(str) {
				return new Promise((resolve, reject) => {
					setTimeout(() => {
						resolve(str);
					}, 5000);
				})
			}

			async function ajax() {
				const r = await getData("zhangsan");
				console.log(r);
				const r1 = await getData(r + "1");
				console.log(r1);
				const r2 = await getData(r1 + "2");
				console.log(r2);
			}

			ajax();
		</script>

	</body>
</html>
